/**
 * 内容展开收起
 * @author: minzhang
 * @update: 2017-03-13
 */

import React, {PropTypes} from 'react';
import { Icon, Row, Col,  } from 'antd';
import styles from './CommonToggle.less';

const CommonToggle = React.createClass({
  getInitialState() {
    return {
    	show: false
    };
  },
	toggle() {
		this.setState({
			show: !this.state.show
		});
	},
	componentWillUnmount () {
		this.setState({
			show: false
		});
	},
  render() {
		const {left, right} = this.props;
		
    return (
      <div>
				<Row className={styles.header}>
					<Col span={left || 4}></Col>
					<Col span={right || 18}><a className={styles.btn} onClick={this.toggle}><Icon type="caret-down" className={styles.icon}/>{this.props.title}</a></Col>
				</Row>
				<div className={styles.body}>{this.state.show ? this.props.body : null}</div>
			</div>
    );
  },
});

CommonToggle.propTypes = {
	title: PropTypes.any,
};

export default CommonToggle;